package no.awi.wpd.unit.model;

import no.awi.wpd.probability.Dice;
import no.awi.wpd.probability.ProbabilityDistribution;

import static no.awi.wpd.probability.ProbabilityDistribution.ONE;
import static no.awi.wpd.probability.ProbabilityDistribution.ZERO;

public enum TroopType {

    INFANTRY(true, ZERO(), false),
    WAR_BEAST(true, ZERO(), false),
    SWARM(true, ZERO(), false),
    CAVALRY(false, ZERO(), false),
    MONSTROUS_INFANTRY(false, ONE(), true),
    MONSTROUS_BEAST(false, ONE(), true),
    MONSTROUS_CAVALRY(false, ONE(), true),
    MONSTER(false, Dice.D6(), false),
    UNIQUE(false, ZERO(), false);

    private final boolean stompable;

    private final ProbabilityDistribution stomp;

    private boolean monstrous;

    TroopType(boolean stompable, ProbabilityDistribution stomp, boolean monstrous) {
        this.stompable = stompable;
        this.stomp = stomp;
        this.monstrous = monstrous;
    }

    public static boolean canStomp(TroopType attacker, TroopType attackee) {
        return stomp(attacker, attackee).equals(ZERO());
    }

    public static ProbabilityDistribution stomp(TroopType attacker, TroopType attackee) {
        return attackee.stompable ? attacker.stomp : ZERO();
    }


    public boolean isMonstrous() {
        return monstrous;
    }

    public int maxSupportAttacks() {
        return isMonstrous() ? 3 : 1;
    }
}
